package TestCases;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

@SuppressWarnings("unused")
public class StringUtil {
    
    private static final Logger LOG = LoggerFactory.getLogger(StringUtil.class);

	public static boolean isEmpty(String str) {
		return str == null || str.isEmpty();
	}


	public static boolean isNotEmpty(String str) {
		return str != null && !str.isEmpty();
	}

	public static boolean isEqual(String str1, String str2) {
		return Objects.equals(str1, str2);
	}
	
	public static boolean isNotEqual(String str1, String str2) {
		return !Objects.equals(str1, str2);
	}
	
	/**
     * String结果对比，得到OK，NG
     * 
     * @param expectedResult
     * @param actualResult
     * @return
     */
    public static String assertResult(String expectedResult, String actualResult) {
        String result;
        if (expectedResult.equals(actualResult))
            result = "OK";
        else
            result = "NG";
        return result;
    }
    
    /**
     * 获取.后的内容
     * 
     * @param
     * @return
     */
	public static String getSubString(String str){
	    int one = str.lastIndexOf(".");
        String Suffix = str.substring((one+1),str.length());
//        System.out.println(Suffix);
        return Suffix;
	}
	
	/**
     * 使用正则表达式去掉多余的.与0
     * 100.00 => 100
     * @param s
     * @return
     */
    public static String subZeroAndDot(String s) {
        if (s.indexOf(".") > 0) {
            // 去掉多余的 0
            s = s.replaceAll("0+?$", "");
            // 如果最后一位是.则去掉
            s = s.replaceAll("[.]$", "");
        }
        return s;
    }
}
